<template>
<div>
  <el-form :inline="true" :model="user" class="demo-form-inline">
    <el-form-item label="账户">
      <el-input v-model="user.username" placeholder="账户"></el-input>
    </el-form-item>
    <el-form-item label="密码">
      <el-input v-model="user.password" placeholder="密码"></el-input>
    </el-form-item>
    <el-form-item label="验证码">
      <el-input v-model="user.code" placeholder="验证码"></el-input>
      <el-image :src="codeURI" @click="getCode"></el-image>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="login">查询</el-button>
    </el-form-item>
  </el-form>
</div>
</template>

<script>
export default {
  name: "loginView",
  data(){
    return{
      user:{},
      codeURI:''
    }
  }, methods:{
    login(){
      this.axios.post("auth/login",this.user).then(res=>{
          if(res.data.code==200){
            this.$message.success(res.data.msg);
            sessionStorage.setItem("token",res.data.data);
            this.$router.push("/index");
          }else {
            this.$message.error(res.data.msg);
          }
      })
    },
    getCode(){
      let  t = new Date().getTime();
      let uuid = sessionStorage.getItem("uid");
      this.user.uuid=uuid;
      this.codeURI='http://localhost:9999/auth/getCode?t='+t+"&uuid="+uuid;
    }
  },created() {
    this.getCode();
  }
}
</script>

<style scoped>

</style>